package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.NursingPlan;
import com.zzyl.nursing.dto.NursingPlanDto;
import com.zzyl.nursing.service.INursingPlanService;
import com.zzyl.nursing.vo.NursingPlanVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理计划Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/nursing/plan" )
@Tag(name = "护理计划相关接口" )
public class NursingPlanController extends BaseController {
    @Autowired
    private INursingPlanService nursingPlanService;

    /**
     * 查询护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:plan:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询护理计划列表" )
    public TableDataInfo list(NursingPlan nursingPlan) {
        startPage();
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        return getDataTable(list);
    }

    /**
     * 导出护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:plan:export')" )
    @Log(title = "护理计划" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出护理计划列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, NursingPlan nursingPlan) {
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        ExcelUtil<NursingPlan> util = new ExcelUtil<NursingPlan>(NursingPlan.class);
        util.exportExcel(response, list, "护理计划数据" );
    }

    /**
     * 获取护理计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:plan:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取护理计划详细信息" )
    public R<NursingPlanVo> getInfo(@Schema(title = "护理计划ID" )
                                    @PathVariable("id" ) Long id) {
        return R.ok(nursingPlanService.selectNursingPlanById(id));
    }


    /**
     * 修改护理计划
     */
    @PreAuthorize("@ss.hasPermi('nursing:plan:edit')" )
    @Log(title = "护理计划" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改护理计划" )
    public AjaxResult edit(@Schema(title = "护理计划实体" ) @RequestBody NursingPlanDto requestParam) {
        return toAjax(nursingPlanService.updateNursingPlan(requestParam));
    }

    /**
     * 删除护理计划
     */
    @PreAuthorize("@ss.hasPermi('nursing:plan:remove')" )
    @Log(title = "护理计划" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除护理计划" )
    public AjaxResult remove(@Schema(title = "护理计划ID数组" ) @PathVariable Long[] ids) {
        return toAjax(nursingPlanService.deleteNursingPlanByIds(ids));
    }

    /**
     * 新增护理计划
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:add')" )
    @Log(title = "护理计划" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid NursingPlanDto requestParam) {
        return toAjax(nursingPlanService.insertNursingPlan(requestParam));
    }
}
